const Tag = require("../models/Tag");
exports.addTag = async function (tagObj) {
  const ins = await Tag.create(tagObj);
  return ins.toJSON()
};

exports.deleteTag = async function (id) {
    await Tag.destroy({                  
        where:{
            id
        }
    })
};

exports.updateTag = async function (id,tagObj) {
    await Tag.update(tagObj,{
        where:{
            id
        }
    })
};


//分页查询
exports.findTags = async function () {
    // const condition = {};
    // if (search) condition.name = { [Op.like]: `%${search}%` };
    const result = await Tag.findAndCountAll();
    return {
      total: result.count,
      list: JSON.parse(JSON.stringify(result.rows)),
    };
  };
  
  exports.findTagById = async function (id) {
    const result = await Tag.findByPk(id);
    return result.toJSON();
  };
